package com.loongtech.bi.action.realTime;

import com.loongtech.bi.manager.realTime.AuanyDisplayByChannelManager;
import com.loongtech.bi.manager.realTime.BossRealTimeManager;
import com.loongtech.bi.manager.system.ConfigManager;
import com.loongtech.bi.manager.system.SysLogManager;
import com.loongtech.bi.support.Session;
import com.loongtech.core.util.Time;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 实时数据-auany分渠道概况Action
 * @author yuri
 * @date 2017年04月11日
 */
@Controller
@Scope("view")
public class AuanyDisplayByChannelAction {
	private Date lookDate = new Date(Time.getBeginningOfDay(Time.currentTime()));  // 前端传过来的查看时间
	private List<AuanyDisplayByChannelManager.AuanyChannelData> channelDatas;
    private String lastUpdateTimeStr = "";  // 前端要访问的最近更新时间字符串
	@Resource
    private AuanyDisplayByChannelManager manager;
    @Resource
    private SysLogManager sysLogManager;
    @Resource
    private ConfigManager configManager;
    @Resource
    private Session session;
    @Resource
    private BossRealTimeManager bossRealTimeManager;
	@PostConstruct
	public void init() {
        channelDatas = new ArrayList<>();
		search();
	}

	public void search() {
		sysLogManager.addLog(session.getUserName(), "实时数据-auany统计概况");
		FacesContext context = FacesContext.getCurrentInstance();
        channelDatas.clear();

        //manager.getSession().clear();

        lastUpdateTimeStr = "最近更新时间为：" + Time.formatTime(System.currentTimeMillis(),Time.TIMEPATTERN_ALL);
        Map<String, AuanyDisplayByChannelManager.AuanyChannelData> res = manager.updateDatas(lookDate);
        if (res == null || res.isEmpty()) {
            context.addMessage(null, new FacesMessage("提示","查询结果为空"));
        } else {
            channelDatas.addAll(res.values());
        }
	}

    public Date getLookDate() {
        return lookDate;
    }

    public void setLookDate(Date lookDate) {
        this.lookDate = lookDate;
    }

    public List<AuanyDisplayByChannelManager.AuanyChannelData> getChannelDatas() {
        return channelDatas;
    }

    public void setChannelDatas(List<AuanyDisplayByChannelManager.AuanyChannelData> channelDatas) {
        this.channelDatas = channelDatas;
    }

    public String getLastUpdateTimeStr() {
        return lastUpdateTimeStr;
    }

    public void setLastUpdateTimeStr(String lastUpdateTimeStr) {
        this.lastUpdateTimeStr = lastUpdateTimeStr;
    }
}
